<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<%@ page import="javax.servlet.http.*,
                com.scalar.chiptrack.utils.ConfigManager" %>


<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/baseProductList.do"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<% HttpSession ses = request.getSession(true); 

  String baseProductName = (String) ses.getAttribute("baseProductName");

  String [] fabProducts =(String [])ses.getAttribute("fabProduct");

  //System.out.println("Fab Products "+fabProducts.length); 
  ses.setAttribute("fabProduct",fabProducts);
  
  %>
<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>
<SCRIPT>

var len = "<%=fabProducts.length%>";
var fabNames = new Array(len);

function whileLoad()
{
	<%
		for( int x=0 ; x < fabProducts.length ; x++)
		{
			if( fabProducts[x]!= null && fabProducts[x].length() > 0 && !fabProducts[x].equals(""))
			{
		%>
			fabNames["<%=x%>"] = "<%=fabProducts[x]%>";
		<%
			}
		}
	%>
}

function func() 
{
	var errors='';
	var errorId = '';
	var pa;
	var emptyName = true;
	var totLen = 0;
	var assemblyNames = null;
	xyz:
	for( var x=0 ; x < fabNames.length ; x++ )
	{
		if( fabNames[x].length > 0 )
		{
			var temp = document.assemblyprocess[fabNames[x]];
			errorId = "errors"+x;

			// to check that no two part numbers are same
			totLen = parseInt(totLen) + temp.length;
			for( var y=0 ; y < temp.length -1 ; y++ )
			{

				temp[y].value = temp[y].value.trim();
				for( var z=y+1 ; z < temp.length ; z++)
				{
					if( temp[y].value!='' && temp[z].value!='' && temp[y].value == temp[z].value)
					{
						errors="<li>Two assembly part numbers cannot be same";
						break xyz;
					}	
				}
			}

			//alert(temp.length);
			// to check atleast one part number
			for( var m=0 ; m < temp.length ; m++)
			{
				temp[m].value = temp[m].value.trim();
				if( temp[m].value.length > 0 )
				{
					emptyName = false;
				}
			}
		
			if( emptyName )
			{
				errors="<li>There should be atleast one assembly part number";
				break xyz;
			}
			else
			{
				emptyName = true;
			}
		}
	}
	assemblyNames = new Array(parseInt(totLen));

	// to check for duplicates in all part numbers
	if( fabNames.length > 1 && errors == '')
	{
		var index  = 0;
		for( var x=0 ; x < fabNames.length ; x++ )
		{
			if( fabNames[x].length > 0 )
			{
				var temp1 = document.assemblyprocess[fabNames[x]];
				for( var y=0 ; y < temp1.length  ; y++ )
				{
					assemblyNames[index] = temp1[y].value ;
					index++;
				}
			}
		}
		xyz2:
		for(var x=0 ; x < assemblyNames.length-1 ; x++ )
		{
			for(var y = x+1 ; y < assemblyNames.length ; y++ )
			{
				if( assemblyNames[x] != '' && assemblyNames[y] != '' && assemblyNames[x] == assemblyNames[y])
				{
					errors="<li>Two assembly part numbers cannot be same";
					errorId = "errors";
					break xyz2;
				}
			}
		}
	}
	if(errors != '')
	{
		for(var l=0 ; l < fabNames.length ; l++)
		{	
			if( fabNames[x].length > 0 )
			{
				pa=document.getElementById("errors"+l);
				pa.innerHTML = "";
			}
		}
		pa=document.getElementById("errors");
		pa.innerHTML = "";
		var pa=document.getElementById(errorId);
		pa.innerHTML = errors;
		return;
	}
	
	document.assemblyprocess.submit();
}


if (document.layers)
  window.setResizable(false);
  var c = 0;

function addMore(assno,count) {
//alert(assno);
var htmltext = '<input type="text" name="'+assno+'" size="20" class="txfield" value=""><br><br>';
var pa=document.getElementById('font'+assno);
pa.insertAdjacentHTML('BeforeEnd',htmltext);

}

function cancel() 
{
	document.assemblyprocess.action ="<%=chipTracContext%>/baseProductList.do";
	document.assemblyprocess.submit();
}
</SCRIPT>
	

<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
</HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onLoad='javascript:whileLoad();'>
<html:form name="assemblyprocess" type="com.scalar.chiptrack.operations.process.forms.AssemblyProcessSplitForm" action="/assemblyprocesssplit" > 

<!-- Top Header Start-->

<%@ include file="/jsp/includes/header.jsp"%>

<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->

<%@ include file="/jsp/operations/operations_menu.jsp" %>

	</TD>
<!-- end of the side navigations -->

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>
<!-- from here your body starts -->

<center><span class="NArialW">Assembly Process Setup</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
<center><chiptrack:errors styleClass="NArialL"/></center>
<center><font class="NArialL"><font color="FF0000"><font id="errors"></font></font></font></center>
<table border="0" width="90%" align=right>
    <tr><td colspan=2><font class="NArialL">Please enter the optional product names you want to do for these products
    	</font></td>  </tr>
    <tr><td colspan=2><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
	<% for(int i=0;i<fabProducts.length;i++)
		{ if(!fabProducts[i].equals(""))  {   %>
	<tr><td colspan='2' class="NArialL" align="left"><font color="FF0000"><font id="errors<%=i%>"></font></font></td></tr>
    <tr>
      <td><font class="NArialL" valign=top>DieBank Product Name : <%=fabProducts[i]%></font></td>
      <td><font class="NArialL">
		<%
		if( request.getAttribute(fabProducts[i]) != null ){
			String[] assmNames = (String[])request.getAttribute(fabProducts[i]);
			for ( int x = 0 ; x < assmNames.length ; x++ )
			{ %>
		      	<input type="text" name="<%=fabProducts[i]%>" size="20" class="txfield" value="<%=assmNames[x] %>"><br><br>
		<%	}
		 } else { %>
      	<input type="text" name="<%=fabProducts[i]%>" size="20" class="txfield" value=""><br><br>
      	<input type="text" name="<%=fabProducts[i]%>" size="20" class="txfield" value=""><br><br>
      	<input type="text" name="<%=fabProducts[i]%>" size="20" class="txfield" value=""><br><br>
		
		<% } %>
		
		<font id='font<%=fabProducts[i]%>'></font>
      	<a href="javascript:addMore('<%=fabProducts[i]%>','<%=i%>')">
		<img src="<%=chipTracContext%>/jsp/includes/images/addmore.gif" border="0"></a>
      </td>
    </tr>
	<tr><td colspan=2><HR width="100%" noShade SIZE=1></td></tr>
	<tr><td colspan=2><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>

	<%}} %>

	<tr><td colspan=2><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
	<tr>
      <td align=center colspan=2>
	  <chiptrack:restrictedLink functionality='<%=Functionality.PRODUCT_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:func();' onmouseover="window.status='Click here to save the Assembly Process';return true" onmouseout="window.status='';return true">
      <img border="0" src="<%=chipTracContext%>/jsp/includes/images/next.gif"></chiptrack:restrictedLink>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <chiptrack:restrictedLink functionality='<%=Functionality.PRODUCT_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:cancel();' onmouseover="window.status='Click here to return to Product List';return true" onmouseout="window.status='';return true">
	  <img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif"></chiptrack:restrictedLink></td>
    </tr>
  </table>



<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->

<%@ include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->
</html:form>
</BODY>
</html>
